package com.ruoyi.common.utils;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.PropertyFilter;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.ognl.Ognl;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.security.MessageDigest;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 字符串工具类
 */
public class StringUtil {

	public static void main(String[] args) throws Exception {
        System.out.println(decoderBy3DES("c235es1owhdoakhdfa53869a", "A6420172B2C53A513AD720C7A44CD956", "UTF-8"));//180123812
        System.out.println(decoderBy3DES(SecureKeyConstant.CONFIG_3DES_KEY,"0BF000EEA050870B23E7777EC80AB577","UTF-8"));
    }

	  /**
     * 参数名按ASCII码生成签名
     * @param map
     * @param key 要排除的项
     * @return
     */
    public static String encodeSign(SortedMap<String,Object> map, String key){
        Set<Map.Entry<String, Object>> entries = map.entrySet();
        Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
        List<String> values =new ArrayList();

        while(iterator.hasNext()){
            Map.Entry entry = iterator.next();
            String k = String.valueOf(entry.getKey());
            String v = String.valueOf(entry.getValue());
            if (StringUtils.isNotEmpty(v) && entry.getValue() !=null && !key.equals(k)) {
                values.add(k + "=" + v);
            }
        }
        return StringUtils.join(values, "&");
    }


    /**
     * 补全固定位数序号
     * @param sourceDate 源数据
     * @param formatLength 固定位数
     * @return
     */
    public static String frontCompWithZore(int sourceDate,int formatLength){
        String newString = String.format("%0"+formatLength+"d", sourceDate);
        return newString;
    }


    /**
     * 空判断
     *
     * @param obj
     * @return
     */
    public static boolean isEmpty(Object obj) {
        if (obj == null)
            return true;
        if (obj instanceof String) {
            return ((String) obj).trim().length() == 0;
        } else {
            return false;
        }
    }

    /**
     * 非空判断
     *
     * @param obj
     * @return
     */
    public static boolean isNotEmpty(Object obj) {
        if (obj == null)
            return false;
        if (obj instanceof String) {
            return ((String) obj).trim().length() > 0;
        } else {
            return true;
        }
    }

    /**
     * 获取UUID（32位）
     *
     * @return
     */
    public static String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 根据最大字节长度拆分字符串
     *
     * @param src
     * @param maxChar
     *            最大字节长度
     * @return
     */
    public static List<String> splitByMaxChar(String src, int maxChar) {
        if (isEmpty(src))
            return null;

        // 未知原因，有时候会多出2字节，保险起见，预留一个字符
        maxChar -= 2;

        List<String> result = new ArrayList<String>();
        int charCount = 0;
        int charStartIndex = 0;
        int charEndIndex = 0;
        for (char c : src.toCharArray()) {
            if (c <= 255) {
                charCount++;
            } else {
                charCount += 2;
            }

            if (charCount > maxChar) {
                result.add(src.substring(charStartIndex, charEndIndex));
                charStartIndex = charEndIndex;
                if (c <= 255) {
                    charCount = 1;
                } else {
                    charCount = 2;
                }
            }

            charEndIndex++;
        }

        if (charStartIndex != charEndIndex) {
            result.add(src.substring(charStartIndex, charEndIndex));
        }

        return result;
    }

    /**
     * 获取指定字节长度字符串
     *
     * @param src
     * @param maxChar
     *            最大字节长度
     * @return
     */
    public static String substringByMaxChar(String src, int maxChar) {
        if (isEmpty(src))
            return null;

        // 未知原因，有时候会多出2字节，保险起见，预留一个字符
        maxChar -= 2;

        int charCount = 0;
        int charEndIndex = 0;
        for (char c : src.toCharArray()) {
            if (c <= 255) {
                charCount++;
            } else {
                charCount += 2;
            }

            if (charCount > maxChar) {
                break;
            }

            charEndIndex++;
        }

        return src.substring(0, charEndIndex);
    }

    /**
     * 获取字符串字节长度
     *
     * @param src
     * @return
     */
    public static int getStringChar(String src) {
        if (isEmpty(src))
            return 0;
        return src.replaceAll("[^\\x00-\\xff]", "**").length();
    }

    public static String list2Str(List<? extends Object> list) {
        if (list == null || list.size() == 0)
            return null;
        StringBuffer sb = new StringBuffer();
        for (Object str : list) {
            sb.append(str).append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

    public static String list2StrWithSQL(List<? extends Object> list) {
        if (list == null || list.size() == 0)
            return null;
        StringBuffer sb = new StringBuffer();
        for (Object obj : list) {
            if (obj instanceof Long) {
                sb.append(obj).append(",");
            } else {
                sb.append("'").append(obj.toString()).append("',");
            }
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

    public static String array2Str(String[] array) {
        if (array == null || array.length == 0)
            return null;
        StringBuffer sb = new StringBuffer();
        for (String str : array) {
            sb.append(str).append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

    /**
     * 3DES加密
     *
     * @param key
     * @param src
     * @param charset
     * @return
     * @throws Exception
     */
    public static String encodeBy3DES(String key, String src, String charset) throws Exception {
        SecretKey secretKey = new SecretKeySpec(key.getBytes(), "DESede");
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);

        byte[] encodeByte = cipher.doFinal(src.getBytes(charset));

        StringBuffer encodeStr = new StringBuffer();
        String temp = null;
        for (int n = 0; n < encodeByte.length; n++) {
            temp = (Integer.toHexString(encodeByte[n] & 0XFF));
            if (temp.length() == 1) {
                encodeStr.append("0");
            }
            encodeStr.append(temp);
        }
        return encodeStr.toString().toUpperCase();
    }

    /**
     * 3DES解密
     *
     * @param key
     * @param encodeStr
     * @param charset
     * @return
     */
    public static String decoderBy3DES(String key, String encodeStr, String charset) throws Exception {
        SecretKey secretKey = new SecretKeySpec(key.getBytes(), "DESede");
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);

        byte[] encodeByte = new byte[encodeStr.length() / 2];
        for (int i = 0; i < encodeByte.length; i++) {
            encodeByte[i] = (byte) Integer.parseInt(encodeStr.substring(2 * i, 2 * i + 2), 16);
        }

        byte[] decoderByte = cipher.doFinal(encodeByte);
        return new String(decoderByte, charset);
    }

    /**
     * 信息安全脱敏
     *
     * @param type
     *            类型 NAME：姓名 CARD：身份证号 PHONE：电话号 ADDRESS：装机地址
     * @param value
     *            脱敏值
     * @return
     */
    public static String desensitization(String type, String value) {
        // 如果入参为空，直接
        if (isEmpty(value) || isEmpty(type)) {
            return "";
        }

        String OGNLName = "((#name == null || #name == '') ? '':((#name.length() > 0 ? #name.substring(0,1) + '*': '')))";
        String OGNLIdCrad = "((#cardNo == null || #cardNo == '') ? '':((#cardNo.length() >= 10 ? #cardNo.substring(0,6) + '********' + #cardNo.substring(#cardNo.length()-4, #cardNo.length()) : #cardNo)))";
        String OGNLMobilePhone = "((#phone == null || #phone == '') ? '': (#phone.length() >= 7 ? (#phone.substring(0,3)+ '****'+ #phone.substring(#phone.length()-4,#phone.length())):((#phone.length() >= 3 ? #phone.substring(0,3):'') + '****')))";
        String OGNLAddress = "((#address == null || #address == '') ? '':((#address.length() >= 7 ? #address.substring(0,6) : #address)+ '******'))";
        String OGNLKDAddress = "((#address == null || #address == '') ? '':((#address.length() >= 10 ? #address.substring(0,#address.length()-15) : #address)+ '******'))";
        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        try {
            if (type.equals("NAME")) {
                map.put("name", value);
                return Ognl.getValue(OGNLName, map, new Object()).toString();
            }
            if (type.equals("CARD")) {
                map.put("cardNo", value);
                return Ognl.getValue(OGNLIdCrad, map, new Object()).toString();
            }
            if (type.equals("PHONE")) {
                map.put("phone", value);
                return Ognl.getValue(OGNLMobilePhone, map, new Object()).toString();

            }
            if (type.equals("ADDRESS")) {
                map.put("address", value);
                return Ognl.getValue(OGNLAddress, map, new Object()).toString();

            }
            if (type.equals("KDADDRESS")) {
                map.put("address", value);
                return Ognl.getValue(OGNLKDAddress, map, new Object()).toString();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 根据淘宝地市编码获取地市名称
     *
     * @param areaCode
     * @return
     */
    public static String getTaobaoCityName(String areaCode) {
        if ("027".equals(areaCode)) {
            return "武汉市";
        } else if ("0701".equals(areaCode)) {
            return "神农架林区";
        } else if ("0702".equals(areaCode)) {
            return "天门市";
        } else if ("0703".equals(areaCode)) {
            return "潜江市";
        } else if ("0710".equals(areaCode)) {
            return "襄樊市";
        } else if ("0711".equals(areaCode)) {
            return "鄂州市";
        } else if ("0712".equals(areaCode)) {
            return "孝感市";
        } else if ("0713".equals(areaCode)) {
            return "黄冈市";
        } else if ("0714".equals(areaCode)) {
            return "黄石市";
        } else if ("0715".equals(areaCode)) {
            return "咸宁市";
        } else if ("0716".equals(areaCode)) {
            return "荆州市";
        } else if ("0717".equals(areaCode)) {
            return "宜昌市";
        } else if ("0718".equals(areaCode)) {
            return "恩施土家族苗族自治州";
        } else if ("0719".equals(areaCode)) {
            return "十堰市";
        } else if ("0722".equals(areaCode)) {
            return "随州市";
        } else if ("0724".equals(areaCode)) {
            return "荆门市";
        } else if ("0728".equals(areaCode)) {
            return "仙桃市";
        } else {
            return areaCode;
        }
    }

    /**
     * 获取Bss地市编码.
     *
     * @param cityCode
     * @return @throws
     */
    public static String getCityCodeBss(String cityCode) {
        if ("0127".equals(cityCode)) {
            cityCode = "1001";
        } else if ("0701".equals(cityCode)) {
            cityCode = "1017";
        } else if ("0724".equals(cityCode)) {
            cityCode = "1010";
        } else if ("0702".equals(cityCode)) {
            cityCode = "1015";
        } else if ("0728".equals(cityCode)) {
            cityCode = "1014";
        } else if ("0715".equals(cityCode)) {
            cityCode = "1008";
        } else if ("0711".equals(cityCode)) {
            cityCode = "1007";
        } else if ("0714".equals(cityCode)) {
            cityCode = "1011";
        } else if ("0719".equals(cityCode)) {
            cityCode = "1009";
        } else if ("0712".equals(cityCode)) {
            cityCode = "1006";
        } else if ("0717".equals(cityCode)) {
            cityCode = "1005";
        } else if ("0716".equals(cityCode)) {
            cityCode = "1018";
        } else if ("0710".equals(cityCode)) {
            cityCode = "1003";
        } else if ("0713".equals(cityCode)) {
            cityCode = "1004";
        } else if ("0722".equals(cityCode)) {
            cityCode = "1012";
        } else if ("0718".equals(cityCode)) {
            cityCode = "1013";
        } else if ("0703".equals(cityCode)) {
            cityCode = "1016";
        } else {
            cityCode = "";
        }
        return cityCode;
    }

	public static String getGroupCityCodeByBoss(String bossCitycode) {
		if ("1001".equals(bossCitycode)) {
			return "8420100";
		} else if ("1017".equals(bossCitycode)) {
			return "8429021";
		} else if ("1010".equals(bossCitycode)) {
			return "8420800";
		} else if ("1015".equals(bossCitycode)) {
			return "8429006";
		} else if ("1014".equals(bossCitycode)) {
			return "8429004";
		} else if ("1008".equals(bossCitycode)) {
			return "8421200";
		} else if ("1007".equals(bossCitycode)) {
			return "8420700";
		} else if ("1011".equals(bossCitycode)) {
			return "8420200";
		} else if ("1009".equals(bossCitycode)) {
			return "8420300";
		} else if ("1006".equals(bossCitycode)) {
			return "8420900";
		} else if ("1005".equals(bossCitycode)) {
			return "8420500";
		} else if ("1018".equals(bossCitycode)) {
			return "8421000";
		} else if ("1003".equals(bossCitycode)) {
			return "8420600";
		} else if ("1004".equals(bossCitycode)) {
			return "8421100";
		} else if ("1012".equals(bossCitycode)) {
			return "8421300";
		} else if ("1013".equals(bossCitycode)) {
			return "8422800";
		} else if ("1016".equals(bossCitycode)) {
			return "8429005";
		} else if ("10".equals(bossCitycode)) {
			return "8420000";
		} else {
			return null;
		}
	}

	/**
	 * 根据集团地市获取boss地市编码.
	 *
	 * @param groupCitycode
	 *            集团地市
	 * @return 本地地市
	 */
	public static String getBossCityCodeByGroup(String groupCitycode) {
		if ("8420100".equals(groupCitycode)) {
			return "1001";
		} else if ("8429021".equals(groupCitycode)) {
			return "1017";
		} else if ("8420800".equals(groupCitycode)) {
			return "1010";
		} else if ("8429006".equals(groupCitycode)) {
			return "1015";
		} else if ("8429004".equals(groupCitycode)) {
			return "1014";
		} else if ("8421200".equals(groupCitycode)) {
			return "1008";
		} else if ("8420700".equals(groupCitycode)) {
			return "1007";
		} else if ("8420200".equals(groupCitycode)) {
			return "1011";
		} else if ("8420300".equals(groupCitycode)) {
			return "1009";
		} else if ("8420900".equals(groupCitycode)) {
			return "1006";
		} else if ("8420500".equals(groupCitycode)) {
			return "1005";
		} else if ("8421000".equals(groupCitycode)) {
			return "1018";
		} else if ("8420600".equals(groupCitycode)) {
			return "1003";
		} else if ("8421100".equals(groupCitycode)) {
			return "1004";
		} else if ("8421300".equals(groupCitycode)) {
			return "1012";
		} else if ("8422800".equals(groupCitycode)) {
			return "1013";
		} else if ("8429005".equals(groupCitycode)) {
			return "1016";
		} else if ("8420000".equals(groupCitycode)) {
			return "10";
		} else {
			return null;
		}
	}

	/**
	 * hrvc地市转集团地市
	 * @param citycode
	 * @return
	 */
	public static String getGroupCityCodeByCityCode(String citycode) {
        if ("0127".equals(citycode)) {
            return "8420100";
        } else if ("0701".equals(citycode)) {
            return "8429021";
        } else if ("0724".equals(citycode)) {
            return "8420800";
        } else if ("0702".equals(citycode)) {
            return "8429006";
        } else if ("0728".equals(citycode)) {
            return "8429004";
        } else if ("0715".equals(citycode)) {
            return "8421200";
        } else if ("0711".equals(citycode)) {
            return "8420700";
        } else if ("0714".equals(citycode)) {
            return "8420200";
        } else if ("0719".equals(citycode)) {
            return "8420300";
        } else if ("0712".equals(citycode)) {
            return "8420900";
        } else if ("0717".equals(citycode)) {
            return "8420500";
        } else if ("0716".equals(citycode)) {
            return "8421000";
        } else if ("0710".equals(citycode)) {
            return "8420600";
        } else if ("0713".equals(citycode)) {
            return "8421100";
        } else if ("0722".equals(citycode)) {
            return "8421300";
        } else if ("0718".equals(citycode)) {
            return "8422800";
        } else if ("0703".equals(citycode)) {
            return "8429005";
        } else if ("0270".equals(citycode)) {
            return "8420000";
        } else {
            return null;
        }
    }

	public static String getCityCodeByGroupCityCode(String commonRegionId){
		String cityCode = null;
		if ("8420100".equals(commonRegionId)){//武汉
			cityCode = "0127";
		}else if ("8420600".equals(commonRegionId)){//襄阳
			cityCode = "0710";
		}else if ("8421100".equals(commonRegionId)){//黄冈
			cityCode = "0713";
		}else if ("8420500".equals(commonRegionId)){//宜昌
			cityCode = "0717";
		}else if ("8420900".equals(commonRegionId)){//孝感
			cityCode = "0712";
		}else if ("8420700".equals(commonRegionId)){//鄂州
			cityCode = "0711";
		}else if ("8421200".equals(commonRegionId)){//咸宁
			cityCode = "0715";
		}else if ("8420300".equals(commonRegionId)){//十堰
			cityCode = "0719";
		}else if (commonRegionId.equals("8420800")){//荆门
			cityCode = "0724";
		}else if ("8420200".equals(commonRegionId)){//黄石
			cityCode = "0714";
		}else if ("8421300".equals(commonRegionId)){//随州
			cityCode = "0722";
		}else if (commonRegionId.equals("8422800")){//恩施
			cityCode = "0718";
		}else if (commonRegionId.equals("8429004")){//仙桃
			cityCode = "0728";
		}else if ("8429006".equals(commonRegionId)){//天门
			cityCode = "0702";
		}else if (commonRegionId.equals("8429005")){//潜江
			cityCode = "0703";
		}else if ("8429021".equals(commonRegionId)){//神农架林区
			cityCode = "0701";
		}else if ("8421000".equals(commonRegionId)){//荆州
			cityCode = "0716";
		}else if ("8420000".equals(commonRegionId)){//湖北
			cityCode = "0270";
		}
		return cityCode;
	}

	/**
     * 地市编号改为区号BSS
     *
     * @param citycode
     * @return
     */
    public static String getOssCityAcct(String citycode) {
    	if ("0127".equals(citycode)) {
            return "8420100";
        } else if ("0701".equals(citycode)) {
            return "8420300";
        } else if ("0724".equals(citycode)) {
            return "8420800";
        } else if ("0702".equals(citycode)) {
            return "8429004";
        } else if ("0728".equals(citycode)) {
            return "8429004";
        } else if ("0715".equals(citycode)) {
            return "8421200";
        } else if ("0711".equals(citycode)) {
            return "8420700";
        } else if ("0714".equals(citycode)) {
            return "8420200";
        } else if ("0719".equals(citycode)) {
            return "8420300";
        } else if ("0712".equals(citycode)) {
            return "8420900";
        } else if ("0717".equals(citycode)) {
            return "8420500";
        } else if ("0716".equals(citycode)) {
            return "8421000";
        } else if ("0710".equals(citycode)) {
            return "8420600";
        } else if ("0713".equals(citycode)) {
            return "8421100";
        } else if ("0722".equals(citycode)) {
            return "8421300";
        } else if ("0718".equals(citycode)) {
            return "8422800";
        } else if ("0703".equals(citycode)) {
            return "8429004";
        } else if ("0270".equals(citycode)) {
            return "8420000";
        }
        return "8420100";
    }

    /**
     * 根据Bss地市获取本地地市编码.
     *
     * @param citybosscode
     *            boss地市
     * @return 本地地市
     */
    public static String getCityCodeByBoss(String citybosscode) {
        if ("1001".equals(citybosscode)) {
            return "0127";
        } else if ("1017".equals(citybosscode)) {
            return "0701";
        } else if ("1010".equals(citybosscode)) {
            return "0724";
        } else if ("1015".equals(citybosscode)) {
            return "0702";
        } else if ("1014".equals(citybosscode)) {
            return "0728";
        } else if ("1008".equals(citybosscode)) {
            return "0715";
        } else if ("1007".equals(citybosscode)) {
            return "0711";
        } else if ("1011".equals(citybosscode)) {
            return "0714";
        } else if ("1009".equals(citybosscode)) {
            return "0719";
        } else if ("1006".equals(citybosscode)) {
            return "0712";
        } else if ("1005".equals(citybosscode)) {
            return "0717";
        } else if ("1018".equals(citybosscode)) {
            return "0716";
        } else if ("1003".equals(citybosscode)) {
            return "0710";
        } else if ("1004".equals(citybosscode)) {
            return "0713";
        } else if ("1012".equals(citybosscode)) {
            return "0722";
        } else if ("1013".equals(citybosscode)) {
            return "0718";
        } else if ("1016".equals(citybosscode)) {
            return "0703";
        } else {
            return null;
        }
    }

    /**
     * 地市编号改为区号
     *
     * @param citycode
     * @return
     */
    public static String getCityCode(String citycode) {
        if ("0127".equals(citycode)) {
            return "027";
        } else if ("0701".equals(citycode)) {
            return "0719";
        } else if ("0724".equals(citycode)) {
            return "0724";
        } else if ("0702".equals(citycode)) {
            return "0728";
        } else if ("0728".equals(citycode)) {
            return "0728";
        } else if ("0715".equals(citycode)) {
            return "0715";
        } else if ("0711".equals(citycode)) {
            return "0711";
        } else if ("0714".equals(citycode)) {
            return "0714";
        } else if ("0719".equals(citycode)) {
            return "0719";
        } else if ("0712".equals(citycode)) {
            return "0712";
        } else if ("0717".equals(citycode)) {
            return "0717";
        } else if ("0716".equals(citycode)) {
            return "0716";
        } else if ("0710".equals(citycode)) {
            return "0710";
        } else if ("0713".equals(citycode)) {
            return "0713";
        } else if ("0722".equals(citycode)) {
            return "0722";
        } else if ("0718".equals(citycode)) {
            return "0718";
        } else if ("0703".equals(citycode)) {
            return "0728";
        }
        return "027";
    }

    /**
     * 前面不补零
     *
     * @param length
     *            补零后的长度
     * @param str
     *            待补零的字符串
     * @return
     */
    public static String addZero(int length, String str) {
        if (str == null)
            return null;
        if (str.length() >= length)
            return str;
        StringBuffer result = new StringBuffer();
        for (int i = str.length(); i < length; i++) {
            result.append("0");
        }
        result.append(str);
        return result.toString();
    }



    public static String toXml(String nodeName, Map<String, Object> param) {
        StringBuffer xml = new StringBuffer();
        if (param != null && param.size() > 0) {
            if (isNotEmpty(nodeName)) {
                xml.append("<").append(nodeName).append(">");
            }
            Iterator<String> it = param.keySet().iterator();
            String key = null;
            Object value = null;
            while (it.hasNext()) {
                key = it.next();
                value = param.get(key);
                xml.append("<").append(key).append(">");
                if (value instanceof String) {
                    xml.append((String) value);
                } else if (value instanceof Map) {
                    xml.append(toXml(null, (Map)value));
                } else if (value instanceof String) {
                    xml.append(value);
                }
                xml.append("</").append(key).append(">");
            }
            if (isNotEmpty(nodeName)) {
                xml.append("</").append(nodeName).append(">");
            }
        }
        return xml.toString();
    }

    /**
	 * 获取指定长度随机数
	 *
	 * @param length
	 * @return
	 */
	public static String getRandomNum(int length) {
		String base = "0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	/**
	 * 将异常日志转换为字符串
	 *
	 * @param e
	 * @return
	 */
	public static String getException(Throwable e) {
		Writer writer = null;
		PrintWriter printWriter = null;
		try {
			writer = new StringWriter();
			printWriter = new PrintWriter(writer);
			e.printStackTrace(printWriter);
			return writer.toString();
		} finally {
			try {
				if (writer != null)
					writer.close();
				if (printWriter != null)
					printWriter.close();
			} catch (IOException e1) { }
		}
	}


	/**
     * 去除空格、制表符、回车、换行
     *
     */
    public static String replaceBlankSpace(String str) {
		if (isEmpty(str)) {
			return str;
		}
		Pattern p = Pattern.compile("\\s*|\t|\r|\n");
		Matcher m = p.matcher(str);
		String destination = m.replaceAll("");
		return destination;
	}

	/***
	 * 判断字符串是否为数字（包含小数点）
	 *
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str) {
		String reg = "^[0-9]+(\\.[0-9]+)?$";
		return str.matches(reg);
	}



    public static String desensitizedName(String fullName){
        if (!StringUtil.isEmpty(fullName)) {
            String name = StringUtils.left(fullName, 1);
            return StringUtils.rightPad(name, StringUtils.length(fullName), "*");
        }
        return fullName;
    }

    public static boolean allNotNull(Object... values) {
        if (values == null) {
            return false;
        } else {
            Object[] var1 = values;
            int var2 = values.length;

            for(int var3 = 0; var3 < var2; ++var3) {
                Object val = var1[var3];
                if (val == null) {
                    return false;
                }
            }

            return true;
        }
    }

    public static String doSign(String content, String charset, String secretKey) {
        String sign = "";
        content = content + secretKey;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(content.getBytes(charset));
            sign = new String(Base64.encodeBase64(md.digest()), charset);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return sign;
    }

    // 顺序组装请求参数，用于签名校验
    public static String assembelSignaturingData(Map data) {
        StringBuilder sb = new StringBuilder();
        TreeMap<String, Object> treeMap = new TreeMap(data);
        for (Map.Entry<String, Object> ent : treeMap.entrySet()) {
            String name = ent.getKey();
            sb.append(name).append('=').append(ent.getValue()).append('&');
        }
        if (sb.length() > 0) {
            sb.setLength(sb.length() - 1);
        }
        return sb.toString();
    }

}
